package com.aote.rs;

import java.io.File;
import java.util.Hashtable;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;

import com.aote.util.PasswordHelper;
import com.browsesoft.EntityManager;
import com.browsesoft.user.User;

@Path("login")
public class Login {

	static Logger log = Logger.getLogger(Login.class);

	@SuppressWarnings("unchecked")
	@GET
	public String login(@QueryParam("name")
	String name, @QueryParam("password")
	String password) {
		log.debug("User Login: " + name);
		User user = EntityManager.getInstance().getUser(name, password,
				PasswordHelper.passwordCamel());
		if (user == null) {
			return null;
		}
		//装载用户属性，用户角色
		String roles = user.getRolesStr();
	    Hashtable attrs = user.attributes;
	    attrs.put("roles",roles);
	    String result =JSONObject.fromObject(attrs).toString(); 
		return result;
	}

}